/**
 * 产品区域渠道价格维护 - 编辑页面
 * @author shixc
 * @date 2018/01/16
 */
define(function () {

    var self,
        app = win.app,
        doc = document,
        vueData = {
            isAdd: false,
            form: '',
            rules: {
                GWAP001: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWAP004: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWAP005: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWAP006: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWAP007: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWAP008: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWAP100: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWAPSITE: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ]
            },
            selectOptions: {
                sys_y_n: app.datas_("sys_y_n"),
                options1: [],
                options2: [],
                options3: [],
                options4: [],
                options5: []
            }
        },
        callObj
    ;

    var Gwai510Edit = app.Module.extend({
        init: function () {
            self = this;
            self._super({
                _tag: 'gwai510_edit',
                _loadTplsFull: [{
                    dom: 'common_open_cp', tpl: 'common/_open_cp'
                }]
            }, win);
        },
        edit: function () {
            app.ajax({
                xurl: 'crm/gwai510/edit',
                xdata: vueData.form,
                loading: true,
                okmsg: '产品区域渠道价格信息修改成功',
                cb: function (result) {
                    if (result.ok) {
                        //同步更新缓存对应的值
                        //callObj.update(result.xdata);
                        app.pageModule('gwai510').reloadTableCurr();
                        layer.close(callObj.layOpenIndex);
                    }
                }
            });
        },
        add: function () {
            app.ajax({
                xurl: 'crm/gwai510/add',
                xdata: vueData.form,
                loading: true,
                okmsg: '产品区域渠道价格信息保存成功',
                cb: function (result) {
                    if (result.ok) {
                        app.pageModule('gwai510').reloadTableCurr();
                        layer.close(callObj.layOpenIndex);
                    }
                }
            });
        },
        _call: function (obj) {
            callObj = obj;
            if (obj.is_add) {
                vueData.isAdd = true;
                app.extendUpLow({
                    target: vueData.form,
                    res: {
                        GWAPACTI: 'Y'
                    },
                    reset: true
                });
            } else {
                vueData.isAdd = false;
                app.extendUpLow({
                    target: vueData.form,
                    res: callObj.data,
                    reset: true
                });
            }

        },
        _ready: function () {
            vueData.form = app.fields_(['GWAP']);
            var vue = new Vue({
                el: '#gwai510_edit',
                data: vueData,
                methods: {
                    cancel: function () {
                        layer.close(callObj.layOpenIndex);
                    },
                    sure: function () {
                        this.$refs['form'].validate(function (valid) {
                            if (valid) {
                                if (vueData.isAdd) {
                                    self.add();
                                } else {
                                    self.edit();
                                }
                            }
                        });
                    },
                    openCp:function () {
                        self._openTplFull({
                            tag: 'common_open_cp',
                            tagData: {
                                cb: function (data) {
                                    vueData.form.GWAP001 = data.GWAM001;
                                },
                            },
                            index: 0,
                            openOpts: {
                                title: '选择产品',
                                area: ['700px', '430px']
                            }
                        });
                    }
                },
                created: function () {
                    self._setEleIsReady('gwai510_edit');
                }
            });
        },
        _lazy: function () {
            app.ajax({
                xurl: 'crm/gwai510/getGwamList',
                cb: function (result) {
                    vueData.selectOptions.options1 = result.data.list;
                }
            });
            app.ajax({
                xurl: 'crm/gwai510/getGweaList',
                cb: function (result) {
                    vueData.selectOptions.options2 = result.data.list;
                }
            });
            app.ajax({
                xurl: 'crm/gwai510/getGwafList',
                cb: function (result) {
                    vueData.selectOptions.options3 = result.data.list;
                }
            });
            app.ajax({
                xurl: 'crm/gwai510/getGwacList',
                cb: function (result) {
                    vueData.selectOptions.options4 = result.data.list;
                }
            });
            app.ajax({
                xurl: 'crm/gwai510/getGwabList',
                cb: function (result) {
                    vueData.selectOptions.options5 = result.data.list;
                }
            });
            this._super();
        }
    });

    return new Gwai510Edit();

});